home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / emstools.arc / EMMLIB.ARC / EMM24_B.ASM < prev    next >
Assembly Source File  |  1990-02-04  |  16KB  |  232 lines

  1. ;-----------------------------------------------------------------------------;
  2. ;      MODULE NAME:   EMM24_B.ASM                                             ;
  3. ;                                                                             ;
  4. ;    FUNCTION NAME:   xchg_memory_region                                      ;
  5. ;                                                                             ;
  6. ;      DESCRIPTION:   This function exchanges a region of memory in any of    ;
  7. ;                     the following memory source/destination combinations.   ;
  8. ;                                                                             ;
  9. ;                        1. conventional memory to conventional memory        ;
  10. ;                        2. conventional memory to expanded memory            ;
  11. ;                        3. expanded memory to conventional memory            ;
  12. ;                        4. expanded memory to expanded memory                ;
  13. ;                                                                             ;
  14. ;                     The term expanded memory region refers only to the area ;
  15. ;                     of memory above 640K bytes (9FFFFh).  If a system       ;
  16. ;                     provides mappable conventional memory, this function    ;
  17. ;                     treats the mappable conventional memory regions as      ;
  18. ;                     ordinary conventional memory.  The contents of the      ;
  19. ;                     source region and the destination region are exchanged. ;
  20. ;                                                                             ;
  21. ;                     The exchange operation can be performed without having  ;
  22. ;                     to save and restore the expanded memory mapping         ;
  23. ;                     context.  The current mapping context is maintained     ;
  24. ;                     throughout this operation.  The length of the region is ;
  25. ;                     limited to the amount of expanded memory allocated to   ;
  26. ;                     the specified EMM handles.  A length of zero is not an  ;
  27. ;                     error however, no exchange will be performed.  A region ;
  28. ;                     length which exceeds 16K bytes is not an error.  In     ;
  29. ;                     this case the function assumes that a group of logical  ;
  30. ;                     pages is the target for the exchange.  The logical page ;
  31. ;                     specified represents the first logical page in which    ;
  32. ;                     the exchange will take place.  If the region length     ;
  33. ;                     exceeds 16K bytes, or if the region is less than 16K    ;
  34. ;                     bytes but spans logical pages, there must be sufficient ;
  35. ;                     logical pages remaining after the first logical page    ;
  36. ;                     for the entire region to fit.                           ;
  37. ;                                                                             ;
  38. ;                     If your application needs to exchange a region of       ;
  39. ;                     conventional memory with expanded memory, you can       ;
  40. ;                     simply exchange it with the region of interest without  ;
  41. ;                     having to perform a save or restore of the current      ;
  42. ;                     mapping context.  An exchange of up to 1M byte may be   ;
  43. ;                     performed, although practical lengths are obviously     ;
  44. ;                     below that value.  Checking is done before starting the ;
  45. ;                     exchange to prevent the possibility of overlap during   ;
  46. ;                     the exchange operation.  Overlapping source and         ;
  47. ;                     destination regions for a exchange are invalid, and the ;
  48. ;                     exchange will not take place.                           ;
  49. ;                                                                             ;
  50. ;           PASSED:   &xs:                                                    ;
  51. ;                        is a far pointer to a structure which contains the   ;
  52. ;                        source & destination information for the exchange.   ;
  53. ;                        The structure members are described here:            ;
  54. ;                                                                             ;
  55. ;                        xs.region_size:                                      ;
  56. ;                           is the length of the memory region to be          ;
  57. ;                           exchanged.                                        ;
  58. ;                                                                             ;
  59. ;                        xs.source_mem_type:                                  ;
  60. ;                           is the type of memory where the source region     ;
  61. ;                           resides.  A value of zero indicates that the      ;
  62. ;                           source region resides in conventional memory.     ;
  63. ;                           A value of one indicates that the source region   ;
  64. ;                           resides in expanded memory.                       ;
  65. ;                                                                             ;
  66. ;                        xs.source_handle:                                    ;
  67. ;                           if the source region resides in expanded memory,  ;
  68. ;                           it specifies the handle number associated with    ;
  69. ;                           the source memory region.  If the source region   ;
  70. ;                           resides in conventional memory, it has no meaning ;
  71. ;                           and should be set to zero for future              ;
  72. ;                           compatibility.                                    ;
  73. ;                                                                             ;
  74. ;                        xs.source_init_offset:                               ;
  75. ;                           is the offset within the source region at which   ;
  76. ;                           to begin the exchange.                            ;
  77. ;                                                                             ;
  78. ;                           If the source region resides in expanded memory,  ;
  79. ;                           it specifies an offset relative to the beginning  ;
  80. ;                           of the 16K-byte source page.  Because the offset  ;
  81. ;                           is relative to the beginning of a 16K-byte source ;
  82. ;                           expanded memory page, it may only take on values  ;
  83. ;                           between 0000h and 3FFFh.                          ;
  84. ;                                                                             ;
  85. ;                           If the source region resides in conventional      ;
  86. ;                           memory, it specifies an offset relative to the    ;
  87. ;                           beginning of the source segment.  Because the     ;
  88. ;                           offset is relative to the beginning of a 64K-byte ;
  89. ;                           conventional memory segment, it may only take on  ;
  90. ;                           values between 0000h and FFFFh.                   ;
  91. ;                                                                             ;
  92. ;                        xs.source_init_log_page_or_seg:                      ;
  93. ;                           is the initial segment or logical page number     ;
  94. ;                           within the source region at which to begin the    ;
  95. ;                           exchange.                                         ;
  96. ;                                                                             ;
  97. ;                           If the source region resides in expanded memory,  ;
  98. ;                           it specifies the logical page within the source   ;
  99. ;                           region at which to begin the exchange.            ;
  100. ;                                                                             ;
  101. ;                           If the source region resides in conventional      ;
  102. ;                           memory, it specifies the initial segment address  ;
  103. ;                           within conventional memory at which to begin      ;
  104. ;                           the exchange.                                     ;
  105. ;                                                                             ;
  106. ;                        xs.dest_mem_type:                                    ;
  107. ;                           is the type of memory where the destination       ;
  108. ;                           region resides.  A value of zero indicates that   ;
  109. ;                           the destination region resides in conventional    ;
  110. ;                           memory (excluding the page frame segment).  A     ;
  111. ;                           value of one indicates that the destination       ;
  112. ;                           region resides in expanded memory.                ;
  113. ;                                                                             ;
  114. ;                        xs.dest_handle:                                      ;
  115. ;                           if the destination region resides in expanded     ;
  116. ;                           memory, it specifies the handle number associated ;
  117. ;                           with the destination memory region.  If the       ;
  118. ;                           destination region resides in conventional, it    ;
  119. ;                           has no meaning and should be set to zero for      ;
  120. ;                           future compatibility.                             ;
  121. ;                                                                             ;
  122. ;                        xs.dest_init_offset:                                 ;
  123. ;                           is the offset within the destination region at    ;
  124. ;                           which to begin the exchange.                      ;
  125. ;                                                                             ;
  126. ;                           If the destination region resides in expanded     ;
  127. ;                           memory, it specifies an offset relative to the    ;
  128. ;                           beginning of the 16K-byte destination page.       ;
  129. ;                           Because the offset is relative to the beginning   ;
  130. ;                           of a 16K-byte source expanded memory page, it may ;
  131. ;                           only take on values between 0000h and 3FFFh.      ;
  132. ;                                                                             ;
  133. ;                           If the destination region resides in conventional ;
  134. ;                           memory, it specifies the offset, relative to the  ;
  135. ;                           beginning of the destination segment, to begin    ;
  136. ;                           the exchange at.  Because the offset is relative  ;
  137. ;                           to the beginning of a 64K-byte conventional       ;
  138. ;                           memory segment, it may only take on values        ;
  139. ;                           between 0000h and FFFFh.                          ;
  140. ;                                                                             ;
  141. ;                        xs.dest_init_log_page_or_seg:                        ;
  142. ;                           is the initial segment or logical page number     ;
  143. ;                           within the destination region at which to begin   ;
  144. ;                           the exchange.                                     ;
  145. ;                                                                             ;
  146. ;                           If the destination region resides in expanded     ;
  147. ;                           memory, it specifies the logical page within the  ;
  148. ;                           destination region at which to begin the          ;
  149. ;                           exchange.                                         ;
  150. ;                                                                             ;
  151. ;                           If the destination region resides in conventional ;
  152. ;                           memory, it specifies the initial segment address  ;
  153. ;                           within conventional memory at which to begin      ;
  154. ;                           the exchange.                                     ;
  155. ;                                                                             ;
  156. ;         RETURNED:   status:                                                 ;
  157. ;                        is the status EMM returns from the call.  All other  ;
  158. ;                        returned results are valid only if the status        ;
  159. ;                        returned is zero.  Otherwise they are undefined.     ;
  160. ;                                                                             ;
  161. ;                     The SOURCE memory region described by:                  ;
  162. ;                           xs.source_handle                                  ;
  163. ;                           xs.source_init_offset                             ;
  164. ;                           xs.source_init_log_page_or_seg                    ;
  165. ;                       is EXCHANGED with the DESTINATION memory region:      ;
  166. ;                           xs.dest_handle                                    ;
  167. ;                           xs.dest_init_offset                               ;
  168. ;                           xs.dest_init_log_page_or_seg                      ;
  169. ;                                                                             ;
  170. ; C USE CONVENTION:   unsigned int     status;                                ;
  171. ;                     MOVE_XCHG_STRUCT xs;                                    ;
  172. ;                                                                             ;
  173. ;                     xs.region_size                 = 640 * 1024;            ;
  174. ;                     xs.source_mem_type             = EXP_MEM;               ;
  175. ;                     xs.source_handle               = 1;                     ;
  176. ;                     xs.source_init_log_page_or_seg = 0;                     ;
  177. ;                     xs.source_init_offset          = 0x0000;                ;
  178. ;                     xs.dest_mem_type               = CONV_MEM;              ;
  179. ;                     xs.des_handle                  = 0;                     ;
  180. ;                     xs.dest_init_log_page_or_seg   = 0x0000;                ;
  181. ;                     xs.dest_init_offset            = 0x0000;                ;
  182. ;                                                                             ;
  183. ;                     status = xchg_memory_region (&xs);                      ;
  184. ;-----------------------------------------------------------------------------;
  185. .XLIST
  186. PAGE    60,132
  187.  
  188. IFDEF SMALL
  189.    .MODEL SMALL, C
  190. ENDIF
  191. IFDEF MEDIUM
  192.    .MODEL MEDIUM, C
  193. ENDIF
  194. IFDEF LARGE
  195.    .MODEL LARGE, C
  196. ENDIF
  197. IFDEF COMPACT
  198.    .MODEL COMPACT, C
  199. ENDIF
  200. IFDEF HUGE
  201.    .MODEL HUGE, C
  202. ENDIF
  203.  
  204. INCLUDE emmlib.equ
  205. INCLUDE emmlib.str
  206. INCLUDE emmlib.mac
  207. .LIST
  208. .CODE
  209.  
  210. xchg_memory_region    PROC                                                  \
  211.             USES DS SI,                                           \
  212.             ptr_xchg_struct:FAR PTR BYTE
  213.  
  214.     ;---------------------------------------------------------------------;
  215.     ;   do;                                                               ;
  216.     ;   .   exchange the contents of a source memory region and a         ;
  217.     ;   .   destination memory region;                                    ;
  218.     ;---------------------------------------------------------------------;
  219.     MOVE        AX, exchange_memory_fcn
  220.     MOVE        DS:SI, ptr_xchg_struct
  221.     INT         EMM_int
  222.  
  223.     ;---------------------------------------------------------------------;
  224.     ;   .   return (EMM status);                                          ;
  225.     ;   end;                                                              ;
  226.     ;---------------------------------------------------------------------;
  227.     RET_EMM_STAT    AH
  228.  
  229. xchg_memory_region    ENDP
  230.  
  231. END
  232.